﻿@inject IWorkContext workContext
@inject LocalizationSettings localizationSettings
@inject CommonSettings commonSettings
@inject IEventPublisher eventPublisher
@inject INopFileProvider fileProvider;
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment WebHostEnvironment
@using System.Globalization
@using Nop.Web.Framework.UI;
@using Nop.Core.Domain.Localization
@using Nop.Services.Common
@inject Nop.Services.Localization.ILanguageService languageService
@{
    //Kendo UI
    var kendoVersion = "2020.1.406";
    var currentKendoCulture = EngineContext.Current.Resolve<IWorkContext>().WorkingLanguage.LanguageCulture;
    var currentCulture = CultureInfo.CurrentCulture;

    //Code to get check if current cultures scripts are exists. If not, select parent cultures scripts
    string GetDefaultLocale()
    {
        var localePattern = NopCommonDefaults.LocalePatternPath;
        var cultureToUse = NopCommonDefaults.DefaultLocalePattern; //Default regionalisation to use

        if (fileProvider.DirectoryExists(fileProvider.Combine(WebHostEnvironment.WebRootPath, string.Format(localePattern, currentCulture.Name))))
            cultureToUse = currentCulture.Name;
        else if (fileProvider.DirectoryExists(fileProvider.Combine(WebHostEnvironment.WebRootPath, string.Format(localePattern, currentCulture.TwoLetterISOLanguageName))))
            cultureToUse = currentCulture.TwoLetterISOLanguageName;

        return cultureToUse;
    }

    var jQueryUI = "1.10.3";

    var supportRtl = workContext.WorkingLanguage.Rtl && !localizationSettings.IgnoreRtlPropertyForAdminArea;

    //CSS resources
    if (supportRtl)
    {
        Html.AppendCssFileParts("~/css/admin/styles.rtl.css");
        Html.AppendCssFileParts("~/lib/adminLTE/css/AdminLTE.rtl.css");
        Html.AppendCssFileParts("~/lib/bootstrap/css/bootstrap.rtl.css");
    }
    else
    {
        Html.AppendCssFileParts("~/css/admin/styles.css");
        Html.AppendCssFileParts("~/lib/adminLTE/css/AdminLTE.min.css");
        Html.AppendCssFileParts("~/lib/bootstrap/css/bootstrap.min.css");
    }

    Html.AppendCssFileParts($"~/lib/datatables/buttons.bootstrap.min.css");
    Html.AppendCssFileParts($"~/lib/datatables/buttons.dataTables.min.css");
    Html.AppendCssFileParts($"~/lib/datatables/datatables.min.css");
    Html.AppendCssFileParts($"~/lib/datatables/css/dataTables.bootstrap.css");
    Html.AppendCssFileParts($"~/lib/kendo/{kendoVersion}/styles/web/kendo.rtl.min.css");
    Html.AppendCssFileParts($"~/lib/kendo/{kendoVersion}/styles/web/kendo.default.min.css");
    Html.AppendCssFileParts($"~/lib/kendo/{kendoVersion}/styles/web/kendo.common.min.css");
    Html.AppendCssFileParts($"~/lib/jquery-ui/jquery-ui-{jQueryUI}/jquery-ui-themes/smoothness/jquery-ui-{jQueryUI}.custom.min.css");
    Html.AppendCssFileParts("~/lib/fontAwesome/css/font-awesome.min.css");
    Html.AppendCssFileParts("~/lib/bootstrap-touchspin/jquery.bootstrap-touchspin.min.css");
    //AdminLTE Skins (choose a skin from the css/skins)
    Html.AppendCssFileParts("~/lib/adminLTE/css/skins/_all-skins.min.css");

    //scripts
    Html.AppendScriptParts($"~/lib/datatables/buttons.bootstrap.min.js");
    Html.AppendScriptParts($"~/lib/datatables/dataTables.buttons.min.js");
    Html.AppendScriptParts($"~/lib/datatables/moment-with-locales-2.22.2.min.js");
    Html.AppendScriptParts($"~/lib/datatables/datatables.min.js");
    Html.AppendScriptParts($"~/lib/datatables/js/dataTables.bootstrap.min.js");
    Html.AppendScriptParts($"~/lib/datatables/js/jquery.dataTables.min.js");
    Html.AppendScriptParts($"~/lib/kendo/{kendoVersion}/js/cultures/kendo.culture.{currentKendoCulture}.min.js");
    Html.AppendScriptParts($"~/lib/kendo/{kendoVersion}/js/messages/kendo.messages.{currentKendoCulture}.min.js");
    Html.AppendScriptParts($"~/lib/kendo/{kendoVersion}/js/kendo.ui.core.min.js");

    Html.AppendScriptParts("~/js/admin.common.js");
    Html.AppendScriptParts("~/lib/jquery-migrate/jquery-migrate-3.1.0.min.js");
    Html.AppendScriptParts($"~/lib/jquery-ui/jquery-ui-{jQueryUI}/jquery-ui-{jQueryUI}.custom.min.js");

    // this file can be downloaded from :
    // https://github.com/johnnyreilly/jquery-validation-globalize
    //Html.AppendScriptParts("https://cdn.jsdelivr.net/gh/johnnyreilly/jquery-validation-globalize@1.0.0/jquery.validate.globalize.min.js");
    Html.AppendScriptParts("~/lib/jquery-validate/jquery.validate.globalize-1.0.0.min.js");

    // globalize scripts
    Html.AppendScriptParts("~/lib/globalize/dist/globalize/currency.min.js");
    Html.AppendScriptParts("~/lib/globalize/dist/globalize/date.min.js");
    Html.AppendScriptParts("~/lib/globalize/dist/globalize/number.min.js");
    Html.AppendScriptParts("~/lib/globalize/dist/globalize.min.js");

    // cldr scripts (needed for globalize)
    Html.AppendScriptParts("~/lib/cldr/dist/cldr/supplemental.min.js");
    Html.AppendScriptParts("~/lib/cldr/dist/cldr/event.min.js");
    Html.AppendScriptParts("~/lib/cldr/dist/cldr.min.js");

    Html.AppendScriptParts("~/lib/jquery-validate/jquery.validate.unobtrusive-v3.2.11/jquery.validate.unobtrusive.min.js");
    Html.AppendScriptParts("~/lib/jquery-validate/jquery.validate-v1.19.1/jquery.validate.min.js");
    Html.AppendScriptParts("~/lib/adminLTE/js/adminlte.min.js");
    Html.AppendScriptParts("~/lib/bootstrap/js/bootstrap.min.js");
    Html.AppendScriptParts("~/lib/bootstrap-touchspin/jquery.bootstrap-touchspin.min.js");
    Html.AppendScriptParts("~/lib/jquery/jquery-3.4.1.min.js");

    //page title
    string adminPageTitle = !string.IsNullOrWhiteSpace(ViewBag.PageTitle) ? ViewBag.PageTitle + " / " : "";
    adminPageTitle += T("Admin.PageTitle").Text;

    //event
    eventPublisher.Publish(new PageRenderingEvent(this.Html));
}
<!DOCTYPE html>
<html lang="@languageService.GetTwoLetterIsoLanguageName(workContext.WorkingLanguage)" @(supportRtl ? Html.Raw(" dir=\"rtl\"") : null)>
<head>
    <title>@adminPageTitle</title>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
    @*Google Font*@
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
    <script>
            var rootAppPath = '@(Url.Content("~/"))';
    </script>
    @Html.NopHeadCustom()
    @Html.NopCssFiles(ResourceLocation.Head, false)
    @Html.NopScripts(ResourceLocation.Head, false)
</head>
<body class="hold-transition skin-blue sidebar-collapse">
    <script type="text/javascript">
            var culture = "@GetDefaultLocale()";

            //load cldr for current culture
            $.when(
                $.get("/lib/cldr-data/supplemental/likelySubtags.json"),
                $.get("/lib/cldr-data/main/" + culture + "/numbers.json"),
                $.get("/lib/cldr-data/main/" + culture + "/currencies.json"),
                $.get("/lib/cldr-data/supplemental/numberingSystems.json"),
                $.get("/lib/cldr-data/main/" + culture + "/ca-gregorian.json"),
                $.get("/lib/cldr-data/main/" + culture + "/timeZoneNames.json"),
                $.get("/lib/cldr-data/supplemental/timeData.json"),
                $.get("/lib/cldr-data/supplemental/weekData.json"),
            ).then(function () {
                // Normalize $.get results, we only need the JSON, not the request statuses.
                return [].slice.apply(arguments, [0]).map(function (result) {
                    return result[0];
                });
            }).then(Globalize.load).then(function () {
                Globalize.locale(culture);
            });
    </script>
    <script>
            kendo.culture("@(currentKendoCulture)");
    </script>
    <div class="wrapper">
        <div class="content-wrapper">
            @await Html.PartialAsync("~/Areas/Admin/Views/Shared/Notifications.cshtml")
            <div>
                <nop-antiforgery-token />
                @RenderBody()
            </div>
        </div>
    </div>
    @Html.NopCssFiles(ResourceLocation.Footer)
    @Html.NopScripts(ResourceLocation.Footer)
    <script>
        $(document).ready(function () {
            //enable tooltips
            $('[data-toggle="tooltip"]').tooltip();
        });
    </script>
</body>
</html>
